#ifndef PAGEUART_H
#define PAGEUART_H

#include <QWidget>
#include <QGroupBox>
#include <QButtonGroup>
#include <QRadioButton>
#include <QCheckBox>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QTextEdit>
#include <QTabWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTimer>
#include <QComboBox>

#include "serialport.h"

class PageUart : public QWidget
{
    Q_OBJECT
public:
    PageUart(QWidget *parent = nullptr);

    void send();

    void findPortManagerPorts();
    void setSerialPort(SerialPort &port);

public slots:
    void onReceiveData(const QByteArray data);
    void onTimeout();
    void onPortChanged(int index);

signals:
    void write(const QByteArray data);

private:
    // controls
    QLabel *lbPort;
    QComboBox *cbPort;

    QRadioButton *rbReceiveASCII;
    QRadioButton *rbReceiveHEX;
    QCheckBox *ckbNewLine;
    QCheckBox *ckbShow;
    QPushButton *pbReceiveClear;

    QRadioButton *rbSendASCII;
    QRadioButton *rbSendHEX;
    QCheckBox *ckbTransfer;
    QCheckBox *ckbPeriod;
    QLineEdit *lePeriod;
    QPushButton *pbSendClear;

    QTextEdit *teDataReceive;

    QLineEdit *leDataSend;
    QPushButton *pbSend;

    QLabel *lbRXTXTimes;
    QLabel *lbRXCnt;
    QLabel *lbTXCnt;
    QPushButton *pbCntClear;

    // statistic
    qint32 rxCnt; //接收字节数
    qint32 txCnt; //发送字节数
    qint32 rxTimes; //接收次数
    qint32 txTimes; //发送次数
    QTimer *timerPeriod;

    // config data
    SerialPort *m_port = nullptr;
    QList<SerialPort*> m_ports;
};

#endif // PAGEUART_H
